package com.cn.jinl.controller;


import com.cn.jinl.api.IOrderBackStorageService;
import com.cn.jinl.domain.BoxManage;
import com.cn.jinl.domain.OrderBackStorage;
import com.cn.jinl.domain.OrderBackStorageRelate;
import com.cn.jinl.domain.OrderBackStorageVo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/orderBackStorage")
public class OrderBackStorageController {

    @Autowired
    private IOrderBackStorageService orderBackStorageService;

    @RequestMapping("/getOrderBackStorageList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OrderBackStorageVo>> getOrderBackStorageList(@PathVariable(value = "frontToken",required = true) String frontToken, @RequestBody QueryForm queryForm) throws Exception{
        JsonResponse<List<OrderBackStorageVo>> response = new JsonResponse<>();
        List<OrderBackStorageVo> backStorages = orderBackStorageService.getOrderBackStorageList(queryForm);
        response.setResult(backStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getOrderBackStorageById/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OrderBackStorage>> getOrderBackStorageById(@PathVariable(value = "frontToken",required = true) String frontToken, String id) throws Exception{
        JsonResponse<List<OrderBackStorage>> response = new JsonResponse<>();
        List<OrderBackStorage> backStorages = orderBackStorageService.getOrderBackStorageById(id);
        response.setResult(backStorages);
        response.setSuccess(true);
        return response;
    }

    //立即入库
    @RequestMapping("/api/addOrderBackStorage")
    @ResponseBody
    public JsonResponse<String> addOrderBackStorage(@RequestBody OrderBackStorage orderBackStorage ) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = orderBackStorageService.addOrderBackStorage(orderBackStorage);
        return CommonUtil.getResponseData(response,result);
    }

    //获取已入库列表
    @RequestMapping("/api/getAPIOrderBackHasStorageList")
    @ResponseBody
    public JsonResponse<List<OrderBackStorageVo>> getAPIOrderBackStorageList(QueryForm queryForm) throws Exception{
        JsonResponse<List<OrderBackStorageVo>> response = new JsonResponse<>();
        List<OrderBackStorageVo> backStorages = orderBackStorageService.getAPIOrderBackHasStorageList(queryForm);
        response.setResult(backStorages);
        response.setSuccess(true);
        return response;
    }

    //已入库列表,查看明细
    @RequestMapping("/api/getAPIOrderBackStorageDetail")
    @ResponseBody
    public JsonResponse<List<OrderBackStorageRelate>> getAPIOrderBackStorageDetail(String backStorageId) throws Exception{
        JsonResponse<List<OrderBackStorageRelate>> response = new JsonResponse<>();
        List<OrderBackStorageRelate> backStorages = orderBackStorageService.getAPIOrderBackStorageDetail(backStorageId);
        response.setResult(backStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/api/addTestOrderBackStorage")
    @ResponseBody
    public JsonResponse<String> addTestOrderBackStorage() throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        OrderBackStorage orderBackStorage = new OrderBackStorage();
        orderBackStorage.setOrderBackId("5deb7ec6orderback-cd4borderback-4c9aorderback-95edorderback-e5d45a11ecc9");
        orderBackStorage.setBackStorageType("1");
        orderBackStorage.setBackUnit("件");
        orderBackStorage.setBackCount("5");
        orderBackStorage.setRemark("备注");
        orderBackStorage.setBackUser("张三");
        List<OrderBackStorageRelate> relates = Lists.newArrayList();
        for(int i =0; i < 5;i++){
            OrderBackStorageRelate relate1 = new OrderBackStorageRelate();
            relate1.setBoxCode("24000001");
            relate1.setGradeValue("55*66");
            relate1.setItemTypeId("伸缩");
            relates.add(relate1);
        }
        orderBackStorage.setRelates(relates);
        String result = orderBackStorageService.addOrderBackStorage(orderBackStorage);
        return CommonUtil.getResponseData(response,result);
    }
}
